var config = require('../../../config.js')
var http = require('../../../utils/httpHelper.js')
Page({
  data: {
    userInfo:{},
    isLogin:false,
    course:{},
    indicatorDots: true,//是否显示面板指示点
    autoplay: true,//是否自动切换
    interval: 5000,//自动切换时间
    duration: 1000,//滑动时间
    buyCount: 1
  },
  onLoad:function(options){
    var that = this;
    let userInfo = wx.getStorageSync('user');
    if (userInfo!=null&&userInfo!=undefined&&userInfo!={}&&userInfo!='') {
      wx.showShareMenu({
        withShareTicket:true,
        menus:['shareAppMessage','shareTimeline']
      })
      that.setData({
        isLogin:true,
        userInfo:userInfo
      })
    }else {
      wx.hideShareMenu();
      wx.setStorageSync('inviteId', options.inviteId);
    }
    var id = options.id;
    that.getCourseInfo(id);
  },
  onShow:function(){
    let userInfo = wx.getStorageSync('user');
    if (userInfo!=null&&userInfo!=undefined&&userInfo!={}&&userInfo!='') {
      this.setData({
        isLogin:true,
        userInfo:userInfo
      })
    }
    if (!this.data.isLogin) {
      wx.hideShareMenu()
    }
  },
  getCourseInfo:function(id){
    var that = this;
    var data = {id:id}
    http.httpGet(config.clubApi.getCourseInfo,data,function(res){
      if(res.code == '200'){
        var course = res.data;
        that.setData({course:course});
      }
    });
  },
  // 分享到朋友圈
  onShareTimeline() {
    var course = this.data.course;
    var url = '/pages/course/detail/index?id='+course.id+'&inviteId='+this.data.userInfo.userId;
    return {
      title: course.courseTitle,
      path: url,
      imageUrl: course.videoCover,
      desc: course.courseContent
    }
  },
  // 转发
  onShareAppMessage() {
    var course = this.data.course;
    var url = '/pages/course/detail/index?id='+course.id+'&inviteId='+this.data.userInfo.userId;
    return {
      title: course.courseTitle,
      path: url,
      imageUrl: course.videoCover,
      desc: course.courseContent
    }
  }
})